// 面板指令
define('companySelectDirective', ['angular'], function (angular) {
    var m = angular.module('directives');
    m.directive('companySelect', ['companyServers',function (companyServers) {
        return {
            restrict: 'AE',
            templateUrl: 'js/templates/companySelect.html',
            replace: true,
            scope:{
                currentId:"=?"
            },
            controller:['$scope','$rootScope',function($scope,$rootScope){
                if(!$rootScope.companyList){
                    companyServers.companyList().then(function (data) {
                        $scope.company = data;
                        $rootScope.companyList=data;
                        $scope.currentCompany=$scope.currentId;
                    });
                }else{
                    $scope.company = $rootScope.companyList;
                }
                               
                $scope.$watch("currentCompany",function(n,o){
                    if(n){
                        $scope.currentId=n;
                    }
                });
                $scope.$watch("currentId",function(n,o){
                    if(n){
                        $scope.currentCompany=n;
                    }else{
                        $scope.currentCompany="";
                    }
                });
            }]
        };
    }]);
});